﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using DDD;
using FloatComparer = UnitTest.TestHelper.FloatComparer;

namespace UnitTest.VertexArray {
    [TestClass]
    public class TestVertexArray_float_vec2_vec3_vec4_ {

        #region Field
        GameWindow window;
        #endregion

        #region Setup
        [TestInitialize ()]
        public void MyClassInitialize () {
            window = new GameWindow ();
        }

        [TestCleanup ()]
        public void MyClassCleanup () {
            window.Dispose ();
            window = null;
        }
        #endregion

        #region TestMethod
        [TestMethod]
        public void TestVertexArray_float () {
            var pos = new float[2] { 1, 2 };
            var varry = new VertexArray<float> (2, 1);
            varry.Set (0, 2, pos);
            
            varry.Compile ();
            varry.Clear ();
            varry.Capture ();

            var buf = new float[2];
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (pos, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void TestVertexArray_vec2 () {

            var pos = new float[4] { 1, 2, 3, 4 };
            var varry = new VertexArray<float> (2, 2);
            varry.Set (0, 2, pos);

            varry.Compile ();
            varry.Clear ();
            varry.Capture ();

            var buf = new float[4];
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (pos, buf, new FloatComparer (0.01f));
        }

        [TestMethod]
        public void TestVertexArray_vec3 () {

            var pos = new float[6] { 1, 2, 3, 4, 5, 6 };
            var varry = new VertexArray<float> (2, 3);
            varry.Set (0, 2, pos);

            varry.Compile ();
            varry.Clear ();
            varry.Capture ();

            var buf = new float[6];
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (pos, buf, new FloatComparer (0.01f));
        }

        [TestMethod]
        public void TestVertexArray_vec4 () {

            var pos = new float[8] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var varry = new VertexArray<float> (2, 4);
            varry.Set (0, 2, pos);

            varry.Compile ();
            varry.Clear ();
            varry.Capture ();

            var buf = new float[8];
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (pos, buf, new FloatComparer (0.01f));
        }
        #endregion

    }
}
